package cn.tedu;

import cn.tedu.seckill.RabbitCompUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.core.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient
@MapperScan("cn.tedu.seckill.mapper")
public class StarterSeckill {
    public static void main(String[] args) {
        SpringApplication.run(StarterSeckill.class,args);
    }
    //声明组件的bean对象
    //队列 seckill_q
    @Bean
    public Queue queue01(){
        //最终,使用这个对象的属性,需要创建声明时,
        //queueDeclare
        return new Queue(
                RabbitCompUtils.Q1,
                false,
                false,
                false,
                null);
    }
    //交换机 seckill_ex
    @Bean
    public DirectExchange ex01(){
        return new DirectExchange(RabbitCompUtils.EX);
    }
    //绑定关系 seckill 路由key
    @Bean
    public Binding bind01(){
        //queue使用seckill绑定交换机
        return BindingBuilder.bind(queue01()).to(ex01())
                .with(RabbitCompUtils.RK);
    }
}
